﻿/*
*应急资源管理子系统
*知识库
*/
IF EXISTS(SELECT NAME FROM SYSOBJECTS WHERE NAME='Proc_GetKnowledges' AND TYPE='P')
BEGIN
  DROP PROCEDURE Proc_GetKnowledges
END
GO
CREATE Procedure Proc_GetKnowledges
 	@pageIndex int,
	@pageSize int,
	@knowledge varchar(20),
	@type varchar(50),
	@emergencyType varchar(50)
	
 AS
DECLARE @SQL nvarchar(1000)
DECLARE @RecordCount int,@P1 INT
DECLARE @Where VARCHAR(200)
IF @PageIndex >1 SET @PageIndex = (@PageIndex-1)*@PageSize +1
SET @Where = ''
IF ((@type IS NOT NULL) AND (RTRIM(LTRIM(@type))<>''))
BEGIN
  SET @Where = @Where +  ' AND Type = '''+ @type + ''''
END
IF ((@emergencyType IS NOT NULL) AND (RTRIM(LTRIM(@emergencyType))<>''))
BEGIN
  SET @Where = @Where +  ' AND EmergencyType = '''+ @emergencyType + ''''
END
IF (@knowledge IS NOT NULL )  AND (RTRIM(LTRIM(@knowledge))<>'')
BEGIN
	SET @Where = @Where +  ' AND Knowledge LIKE ''%'+ @knowledge + '%'''
END
IF ((LEN(@Where)>0) AND (LEFT(@Where,5)=' AND')) 
BEGIN
	SET @Where = Right(@Where,LEN(@Where)-5)
END
SET @SQL = N'SELECT * FROM  Eaer_Knowledge ORDER BY ReleaseDate DESC'
IF (LEN(@Where)>0)
BEGIN
  SET @SQL = 'SELECT * FROM  Eaer_Knowledge WHERE ' + @Where + ' ORDER BY ReleaseDate DESC'
END
EXEC sp_cursoropen @P1 OUTPUT, @SQL, @scrollopt = 1, @ccopt = 335873, @rowcount = @RecordCount OUTPUT 
IF (@P1 != 0)
BEGIN
  EXEC sp_cursorfetch @P1, 32, @PageIndex, @PageSize 
  EXEC sp_cursorclose @P1
END
select @RecordCount
return @@ERROR 